package com.eternal.log.adapter;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.eternal.base.database.entity.Log;
import com.eternal.base.protocol.ProtocolTransformer;
import com.eternal.log.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class LogCHolder extends RecyclerView.ViewHolder {
    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("h:mm aa — ", Locale.ENGLISH);
    private TextView time, content;

    public LogCHolder(@NonNull ViewGroup parent) {
        this(parent, R.layout.log_item_content);
    }

    public LogCHolder(@NonNull ViewGroup parent, @LayoutRes int layout) {
        super(LayoutInflater.from(parent.getContext()).inflate(layout, parent, false));
        time = itemView.findViewById(R.id.tv_log_time);
        content = itemView.findViewById(R.id.tv_log_info);
    }

    public Date init(Log log, long start, boolean isDegree) {
        if (log.time > start) {
            time.setTextColor(0xff15baff);
            content.setTextColor(0xff15baff);
        } else {
            time.setTextColor(0xffffffff);
            content.setTextColor(0xffffffff);
        }
        Date result = new Date(log.time);
        time.setText(FORMAT.format(result));
        content.setText(ProtocolTransformer.getLogCString(log, isDegree));
        return result;
    }
}
